package com.heima.admin.job;

import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.feigns.WemediaFeign;
import com.heima.model.common.dtos.ResponseResult;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class WeMediaNewsAutoScanJob {

    @Autowired
    WemediaFeign wemediaFeign;

    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;
    //定时扫描待发布文章
    @XxlJob("womediaAutoScanjob")
    public ReturnT autoScanJob(String param){
        log.info("自媒体文章审核调度任务开始执行....");
        //1. 远程调用wemedia 查询待发布文章id 列表
        ResponseResult<List<Integer>> release = wemediaFeign.findRelease();
        if (release.getCode().intValue() != 0) {
            log.error("定时调度任务执行失败=====>" + release.getErrorMessage());
            return ReturnT.FAIL;
        }
        List<Integer> data = release.getData();
        if (CollectionUtils.isNotEmpty(data)) {
            for (Integer datum : data) {
                //2. 调用自动审核发布方法 发布文章
                wemediaNewsAutoScanService.autoScanByMediaNewsId(datum);
            }
        }
        log.info("自媒体文章审核调度任务执行结束...");
        return ReturnT.SUCCESS;
    }

}
